package com.nsgf.library.ui.page.fragment;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.kunminx.architecture.ui.page.DataBindingConfig;
import com.kunminx.architecture.ui.state.State;
import com.nsgf.library.BR;
import com.nsgf.library.R;
import com.nsgf.library.data.bean.LibraryInfo;
import com.nsgf.library.databinding.FragmentNsgfHomeWorkSituationBinding;
import com.nsgf.library.domain.request.AccountRequester;
import com.nsgf.library.ui.adapter.HomeLabelGateListAdapter;
import com.nsgf.library.ui.page.BaseFragment;
import com.nsgf.library.ui.page.StateHolder;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class HomeWorkSituationFragment extends BaseFragment {

    public static HomeWorkSituationFragment newInstance(List<LibraryInfo> datas) {
        HomeWorkSituationFragment messageFragment = new HomeWorkSituationFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("datas", (Serializable) datas);
        messageFragment.setArguments(bundle);
        return messageFragment;

    }

    private List<LibraryInfo> getType() {
        return (List<LibraryInfo>) getArguments().getSerializable("datas");
    }

    private MessageFragmentStates mStates;

    private HomeLabelGateListAdapter mAdapter;


    @Override
    protected void initViewModel() {
        mStates = getActivityScopeViewModel(MessageFragmentStates.class);
    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {

        mAdapter = new HomeLabelGateListAdapter(getContext());

        return new DataBindingConfig(R.layout.fragment_nsgf_home_work_situation, BR.vm, mStates)
                .addBindingParam(BR.adapter, mAdapter);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mBinding = (FragmentNsgfHomeWorkSituationBinding) getBinding();
        List<LibraryInfo> infos = getType();
        mStates.listGate.set(infos);
        mAdapter.notifyDataSetChanged();

    }

    private FragmentNsgfHomeWorkSituationBinding mBinding;


    public static class MessageFragmentStates extends StateHolder {

        public final State<String> name = new State<>("");

        public final State<List<LibraryInfo>> listGate = new State<>(new ArrayList<>());

        public final State<Boolean> loadingVisible = new State<>(false);

    }
}
